#include "internal.h"

/*
 * __pick_next_task_dl - Helper to pick the next -deadline task to run.
 * @rq: The runqueue to pick the next task from.
 */
static struct task_struct *__pick_task_dl(struct rq *rq)
{
    struct sched_dl_entity *dl_se;
    struct dl_rq *dl_rq = &rq->dl;
    struct task_struct *p;

again:
    if (!sched_dl_runnable(rq))
        return NULL;

    dl_se = pick_next_dl_entity(dl_rq);
    WARN_ON_ONCE(!dl_se);

    if (dl_server(dl_se))
    {
        p = dl_se->server_pick_task(dl_se);
        if (!p)
        {
            if (!dl_server_stopped(dl_se))
            {
                dl_se->dl_yielded = 1;
                update_curr_dl_se(rq, dl_se, 0);
            }
            goto again;
        }
        rq->dl_server = dl_se;
    }
    else
    {
        p = dl_task_of(dl_se);
    }

    return p;
}

static struct task_struct *pick_task_dl(struct rq *rq)
{
    return __pick_task_dl(rq);
}
